#include <iostream>
#include <stdio.h>
#include <stdlib.h> 

using namespace std;

int lookup(int *array,int i,int arrlen){
	printf("%d\n",arrlen); 
	int j = 0;
	while (j < arrlen){
		if (array[j]==i){
			return j;
		}
		j++;
	}
	return -1;
} 

int lookup_re(int *arr,int target,int start,int end){
	int mid = (end+start)/2;
	int midnum = arr[mid];
	if (target > arr[end]){
		return -1;
	}
	if (target < arr[start]){
		return -1;
	}
	//当 start 和 end 相邻时 
	if (end-start==1){
		if (arr[start]==target){
			return start+1;
		}
		if (arr[end]==target){
			return end+1;
		}
		return -1;
	}
	// 寻找中位数 
	if (target>midnum){
		lookup_re(arr,target,mid,end);
	}else if (target<midnum){
		lookup_re(arr,target,start,mid);
	}else {
		return mid+1;
	}
}


int main(){
	int arr[] = {11,22,33,44,55,66,77,88,99,100};
	int a = 0;
	while(1){
		printf("input:");
		scanf("%d",&a);
		int i = lookup_re(arr,a,0,9);
		if (i==-1)
			printf("没找到诶！\n");
		else 
			printf("找到了，在第%d位\n",i);
	}
	return 0;	
}
